var webName="/projectajax1.0/UserServlet?type=";
$(function(){
	var obj={
			"table":"student",
			"item":{"name":"刘德华"}
		};
	
	initData();
})

function initData(){
	$('#tab1').datagrid({   
	    url:'UserServlet?type=getUserPage',    
	    columns:[[    
	        {field:'id',title:'编号',width:100},    
	        {field:'name',title:'姓名',width:100},    
	        {field:'pwd',title:'密码',width:100,align:'right'},
	        {field:'rinfo',title:'角色',width:100,align:'right',formatter:function(value,row,index){
	        	return value.name;
	        }},
	        {field:'a',title:'操作',width:100,align:'right',formatter:function(value,row,index){
	        	return "<a href='javascript:deleteInfo("+row.id+")'>删除</a>&nbsp;<a href='javascript:updateInfo("+row+")'>编辑</a>";
	        }},
	    ]],
	    pagination:true,
	    rownumbers:true,
	    singleSelect:true,
	    pageSize:5,
	    pageList:[5,10,15,20,30],
	    toolbar: '#tb',
	    toolbar: [{
			iconCls: 'icon-add',
			handler: function(){
				$('#win').window({    
				    width:400,    
				    height:200,    
				    modal:true,
				    title:'添加信息'
				});
			}
		}],
		onDblClickRow:function(rowIndex,rowData){
			updateInfo(rowData);
		}
	});  
}


function deleteInfo(id){
	$.get(webName+"deleteUser",{"id":id},function(data){
		if(data==1){
			initData()
			//loadList(1,10);
		}
		else
			alert('服务器异常,请联系管理员');
		})       
	   
	
}

function updateInfo(rowData){
	$("#name").val(rowData.name)
	$("#pwd").val(rowData.pwd)
	//$("#select").val(rowData.rinfo.id)
	$('#win').window({    
	    width:400,    
	    height:200,    
	    modal:true,
	    title:'编辑'+rowData.name+'的信息'
	});
}

function doUpdate(){
	alert("a")
	var id=$("#id").val()
	var id=$("#name").val()
	var id=$("#pwd").val()
	
	$.post(webName+"updateUser",{"id":id,"name":name,"pwd":pwd,"rolesid":2},function(data){
		if(data==1){
			alert("成功");
			initData()
			//loadList(1,10);
		}else{
			alert("失败")
		}
	})
	$('#win').window('close');
}


























